package com.lfg.leetcode.leetcode0;


public class No50myPow {

    public static void main(String[] args) {
        double ret = myPow(2.00000, -2147483648);
        System.out.println(ret);
    }

    public static double myPow(double x, int n) {
        long N = n;
        if (N < 0) return 1.0 / pow(x, -N);
        return pow(x, n);
    }

    public static double pow(double x, long n) {
        if (n == 0) return 1;
        if (n == 1) return x;
        if (x == 1) {
            return x;
        }
        double ret = 1;
        double v = x;
        while (n > 0) {
            if ((n & 1) == 1) {
                ret *= v;
            }
            v *= v;

            n = n >> 1;
        }
        return ret;
    }


}

